import { defineStore } from 'pinia'

const token = localStorage.getItem('token')
const userInfo = localStorage.getItem('userInfo')
export const useUser = defineStore('user', {
  state: () => ({
    token: token || '',
    userInfo: userInfo || {},
  }),
  actions: {
    setToken(token) {
      this.token = token
      localStorage.setItem('token', token)
    },
    setUserInfo(userInfo) {
      this.userInfo = userInfo
      localStorage.setItem('userInfo', userInfo)
    },
    logout() {
      this.token = ''
      this.userInfo = {}
      uni.setStorageSync('token', '')
    },
  },
})
